<template>
  <ContentWrap>
    <ContainerTitle :title="title"></ContainerTitle>
    <BaseInfo v-if="stepName === 'baseInfo'" v-model="stepName" :is-edit="isEdit" next="inspectionPersonList" :step-data="stepData" @on-refresh="onRefreshHandle"></BaseInfo>
    <InspectionPersonList v-else-if="stepName === 'inspectionPersonList'" v-model="stepName" :is-edit="isEdit" next="beInspecBtedPersonList" prev="baseInfo" :step-data="stepData" @on-refresh="onRefreshHandle"></InspectionPersonList>
    <BeInspecBtedPersonList v-else-if="stepName === 'beInspecBtedPersonList'" v-model="stepName" :is-edit="isEdit" next="inspectionWay" prev="inspectionPersonList" :step-data="stepData" @on-refresh="onRefreshHandle"></BeInspecBtedPersonList>
    <InspectionWay v-else-if="stepName === 'inspectionWay'" v-model="stepName" :is-edit="isEdit" next="contentFilter" prev="beInspecBtedPersonList" :step-data="stepData" @on-refresh="onRefreshHandle"></InspectionWay>
    <ContentFilter v-else-if="stepName === 'contentFilter'" v-model="stepName" :is-edit="isEdit" prev="inspectionWay" :step-data="stepData"></ContentFilter>
  </ContentWrap>
</template>
<script>
import ContentWrap from '@/components/ContentWrap'
import BaseInfo from './components/baseInfo'
import InspectionPersonList from './components/inspectionPersonList'
import BeInspecBtedPersonList from './components/beInspectedPersonList'
import InspectionWay from './components/inspectionWay'
import ContentFilter from './components/contentFilter'
import ContainerTitle from '../components/containerTitle.vue'
import { qualityCheckProjectDetail } from '@/api/inspection'

const stepTitleList = { baseInfo: '基础信息', inspectionPersonList: '质检人名单', beInspecBtedPersonList: '受检人名单', inspectionWay: '质检方式', contentFilter: '内容筛选' }
export default {
  name: 'AddEditItem',
  components: {
    ContentWrap,
    BaseInfo,
    InspectionPersonList,
    BeInspecBtedPersonList,
    InspectionWay,
    ContentFilter,
    ContainerTitle
  },
  data() {
    return {
      stepData: {},
      stepName: 'baseInfo',
      id: undefined
    }
  },
  computed: {
    isEdit() {
      return !this.$validateNone(this.$route.params.id)
    },
    title() {
      return stepTitleList[this.stepName]
    }
  },
  created() {
    if (this.isEdit) {
      this.onRefreshHandle(this.$route.params.id)
    }
  },
  methods: {
    // 数据发生变化
    onRefreshHandle(id) {
      if (this.$validateNone(id)) {
        id = this.id
      } else {
        this.id = id
      }
      qualityCheckProjectDetail(id).then(res => {
        this.stepData = res.data
      })
    }
  }
}
</script>
<style lang="scss" module>
</style>
